package cn.angis.flow.service;

import cn.angis.flow.adapter.TransferAdapter;
import cn.angis.flow.adapter.WarmFlowAdapter;
import cn.angis.flow.vo.WarmFlowInteractiveTypeVo;
import org.dromara.warm.flow.core.service.DefService;
import org.dromara.warm.flow.core.service.NodeService;
import org.dromara.warm.flow.core.service.SkipService;
import org.noear.solon.Solon;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Init;
import org.noear.solon.annotation.Inject;
import org.noear.solon.data.annotation.Transaction;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 流程定义serviceImpl
 *
 * @author warm
 * @since 2023/5/29 13:09
 */
@Component
public class HhDefService {

    @Inject
    private DefService defService;

    @Inject
    private NodeService nodeService;

    @Inject
    private SkipService skipService;

    private static final List<WarmFlowAdapter> WARM_FLOW_ADAPTERS = new ArrayList<>();

    /**
     * 初始化方法
     */
    @Init
    public void initMethod() {
        List<WarmFlowAdapter> beanNamesForType = Solon.app().context().getBeansOfType(WarmFlowAdapter.class);
        WARM_FLOW_ADAPTERS.addAll(beanNamesForType);
    }

    @Transaction
    public Boolean interactiveType(WarmFlowInteractiveTypeVo warmFlowInteractiveTypeVo) {
        Integer operatorType = warmFlowInteractiveTypeVo.getOperatorType();
        for (WarmFlowAdapter warmFlowAdapter : WARM_FLOW_ADAPTERS) {
            if (warmFlowAdapter.isAdapter(operatorType)) {
                return warmFlowAdapter.adapter(warmFlowInteractiveTypeVo);
            }
        }
        return false;
    }
}
